<template>
	<view class="uiwu">
		<view style="height: 94rpx;">
			<view class="uiwu-scroll">
				<scroll-view scroll-x>
					<view class="uiwu-scroll-list uiwu-flex-align">
						<view v-for="(item, index) in menuTablist" class="item"
							:class="index == activeIndex ? 'active' : ''" :key="index" @click="swiperTap(item, index)">
							{{ item }}
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<uiwu-list loading="noMore">
			<view class="uiwu-list">
				<view class="uiwu-list-item uiwu-flex-align" v-for="(item, index) in listData" :key="index"
					@tap="uiwu.openWindow(`/pages/AfterSales/detail?id=${item.id}&type=${activeIndex}`)">
					<image :src="item.product_image || item.image" mode="aspectFill"></image>
					<view class="in uiwu-flex-column">
						<view class="title uiwu-flex-space">
							<text style="flex: 1;">{{ item.product_name || item.store_name }}</text>
							<text>{{ getStatus(item.refund_status, item.is_refund) }}</text>
						</view>
						<view class="time">{{ uiwu.formatTimestamp(item.refund_time ? item.refund_time * 1000 :
							item.add_time * 1000) }}</view>
					</view>
				</view>
			</view>
		</uiwu-list>
	</view>
</template>

<script setup lang="ts">
import { uiwu } from '@/api/interface/interface';
import { integralRefundlist, refundlist } from '@/api/interface/prize';
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
import { inject, ref } from 'vue';
const menuTablist = ref<Array<string>>(['积分订单', '奖品订单'])
const activeIndex = ref(0)
const listData = ref<Array<object>>([])
const pageNum = ref<number>(1)
const more = ref<string>('loading');
const isLock = ref<boolean>(true)
const swiperTap = (item, index) => {
	activeIndex.value = index
	getrefundlist()
}
const getrefundlist = async (mack: boolean = false): Promise<any> => {
	if (!mack) pageNum.value = 1
	const postData = {
		page: pageNum.value,
	}
	const { data: { data, total } } = activeIndex.value == 0 ? await integralRefundlist(postData) : await refundlist(postData);
	isLock.value = true
	uiwu.setlist({
		isMore: mack,
		listData,
		total,
		listRow: data,
		more,
		pageNum
	})
}
const getStatus = (type, status) => {
	return type == 1 ? '等平台审核' : type == 2 && status == 0 ? '售后完成' : type == 2 && status == 1 ? '待寄回商品' : type == 4 ? '待平台收货' : type == 5 ? '售后完成' : '审核不通过'
}
onReachBottom(() => {
	if (!isLock.value) return
	isLock.value = false
	pageNum.value++
	getrefundlist(true)
})
onLoad(() => {
	getrefundlist()
})

</script>

<style lang="scss">
page {
	background-color: #f6f6f6;
}

.uiwu {
	padding-top: 20rpx;
}

.uiwu-scroll {
	background-color: #272323;
	width: 100%;
	height: 94rpx;
	position: fixed;
	left: 0;
	right: 0;
	top: 0;
	/* #ifdef H5 */
	//top: 44px;
	/* #endif */
	z-index: 90;

	&-list {
		//padding: 34rpx;
		padding-left: 34rpx;
		height: 94rpx;

		.item {
			flex-shrink: 0;
			font-size: 28rpx;
			font-weight: 500;
			color: #FFFFFF;
			height: 55rpx;
			line-height: 55rpx;
			margin-right: 50rpx;

			&.active {
				text-align: center;
				width: 176rpx;
				// background: url('../../static/indextab.png') no-repeat 0 0;
				// background-size: 100% 100%;
				font-size: 32rpx;
				font-family: PingFang SC-Heavy, PingFang SC;
				font-weight: 800;
				color: #FFFFFF;
				line-height: inherit;
				text-shadow: 0px 4rpx 0rpx #231815;
			}
		}
	}
}

.uiwu-list {
	padding: 0 24rpx;
	background-color: #fff;

	&-item {
		padding: 24rpx 0;

		image {
			width: 136rpx;
			height: 136rpx;
			border-radius: 16rpx;
			margin-right: 24rpx;
		}

		.in {
			flex: 1;
			height: 136rpx;
			justify-content: space-around;
		}

		.title {
			text {
				font-size: 28rpx;
				font-weight: 800;
				color: #231815;

				&:nth-child(2) {
					color: #EF821E;
					font-weight: 400;
				}
			}
		}

		.jifen {
			font-size: 24rpx;
			font-weight: 500;
			color: #444444;
		}

		.time {
			font-size: 24rpx;
			font-weight: 300;
			color: #999999;
		}
	}
}
</style>
